import '../helper/dioHelper.dart';

class AppVersion {
  int ID;
  String APPGUID;
  String VersionName;
  int VersionCode;
  String Introduce;
  String Debug;
  String NewFeatures;
  String CreateTime;
  String FileId;

  AppVersion(
      this.ID,
      this.APPGUID,
      this.VersionName,
      this.VersionCode,
      this.Introduce,
      this.Debug,
      this.NewFeatures,
      this.CreateTime,
      this.FileId);
  AppVersion.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        APPGUID = json["APPGUID"],
        VersionName = json["VersionName"],
        VersionCode = json["VersionCode"],
        Introduce = json["Introduce"],
        Debug = json["Debug"],
        NewFeatures = json["NewFeatures"],
        CreateTime = json["CreateTime"],
        FileId = json["FileId"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'APPGUID': APPGUID,
        'VersionName': VersionName,
        'VersionCode': VersionCode,
        'Introduce': Introduce,
        'Debug': Debug,
        'NewFeatures': NewFeatures,
        'CreateTime': CreateTime,
        'FileId': FileId,
      };
  static Future<bool> Add(AppVersion x1) async {
    var response = await DioHelper.Post("/AppVersion/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(AppVersion x1) async {
    var response = await DioHelper.Post("/AppVersion/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(AppVersion x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/AppVersion/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<AppVersion?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/AppVersion/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200)
      return new AppVersion.fromJson(response.data);
    return null;
  }

  static Future<List<AppVersion>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/AppVersion/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 =  <AppVersion>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new AppVersion.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<AppVersion>> GetAllList() async {
    var response = await DioHelper.Get("/AppVersion/GetAllList", {});
    var list1 = <AppVersion>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new AppVersion.fromJson(x));
      }
    }
    return list1;
  }

  static Future<AppVersion?> GetNew(String guid) async {
    var response = await DioHelper.Get("/AppVersion/GetAppNew?Guid=$guid", {});
    //var list1 = new List<AppVersion>();
    if (response.statusCode == 200) {
      if(response.data==null)
      return null;
      return AppVersion.fromJson(response.data);
    }
    return null;
  }
}
